
/* ______________________________________________________________________

	Random Number Generator
	This tool generates and returns a random number.

	If no parameters ar passed, result is a random number between 0.0 and 1.0
	If only one parameter is passed, result is a number between 0 and min
	If both parameters are passed, result is a number between min and max

	Eneko Alonso [ealonso@level-studios.com]
	November 2008
   ______________________________________________________________________
*/

var Random = function(min, max) {
	min = parseInt(min);
	max = parseInt(max);

	if ($defined(min)) {
		if (!$defined(max)) {
			max = min;
			min = 0;
		}
	} else {
		return Math.random();
	}
	
	if (min > max) {
		// Swap variables
		min = min ^ max;
		max = min ^ max;
		min = min ^ max;
	}

	return Math.floor(Math.random() * (max - min + 1) + min);
}
